<template>
  <div class="flex flex-col">
    <div class="px-10px dropBusinesslist overflow-auto flex-1">
      <PullRefresh v-model="refreshing" @refresh="onRefresh">
        <List
          v-model="loading"
          :finished="finished"
          finished-text="没有更多了"
          :immediate-check="false"
          @load="onLoad"
        >
          <!-- <cardList
            :list="list"
            @Details="Details"
            :active="active"
            @update="update"
          ></cardList> -->
          <cardListVue
            :list="list"
            active="dropBusiness"
            @Details="Details"
          ></cardListVue>
        </List>
      </PullRefresh>
    </div>
  </div>
</template>

<script>
import cardListVue from "../components/cardList.vue";
import { falling } from "@/services/business/HighSeas.js";
import { PullRefresh, List, Toast } from "vant";
import Bus from "@/config/evenrBus";
export default {
  components: {
    cardListVue,
    PullRefresh,
    List,
  },
  data() {
    return {
      list: [],
      refreshing: false, //下拉刷新
      loading: false, //列表加载
      finished: false,
    };
  },
  created() {
    this.get_falling();
  },
  mounted() {
    Bus.$on("updatefalling", this.get_falling);
  },
  methods: {
    get_falling() {
      falling()
        .then((data) => {
          this.list = data;
          this.refreshing = false;
          this.loading = false;
          this.finished = true;
        })
        .catch((err) => {
          Toast(err);
          this.refreshing = false;
          this.loading = false;
        });
    },
    onRefresh() {
      this.refreshing = true;
      this.loading = true;
      this.get_falling();
    },
    onLoad() {
      this.get_falling();
    },
    // 进入详情
    Details(val) {
      console.log(val);
      let belongLib;
      // 1：沉寂库，2：公海:3：临时库:4：私海
      switch (val.belongLib) {
        case 1:
          belongLib = "HighSeas";
          break;
        case 2:
          belongLib = "SilentLibrary";
          break;
        case 3:
          belongLib = "TemporaryLibrary";
          break;
        case 4:
          belongLib = "PrivateSea";
          break;
      }
      console.log(val.belongLib);
      Bus.$emit("Details", val.id);
      this.$router.push({ name: belongLib, query: { id: val.id } });
    },
  },
  destroyed() {
    Bus.$off("Details");
    Bus.$off("updatefalling");
  },
};
</script>

<style lang="scss" scoped>
.dropBusinesslist {
  // height: calc(100vh - 80px);
  margin: 0 auto 12px;
}
</style>
